package com.hspedu.newData.dmsxl.贪心算法.easy;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-27 
 * @Version: 1.0
 */

// todo
public class LC860柠檬水找零 {

    public boolean lemonadeChange(int[] bills) {

        int[] change = new int[2];

        for (int i = 0; i < bills.length; i++) {

            if (bills[i] == 5){
                change[0]++;
            } else if (bills[i] == 10) {
                change[0]--;
                change[1]++;
            }else {
                if (change[1] > 0){
                    change[1]--;
                    change[0]--;
                }else {
                    change[0] -= 3;
                }
            }
            if (change[0]<0){
                return false;
            }
        }
        return change[0] >= 0;
    }

    @Test
    public void test() {
        // 测试代码

        lemonadeChange(new int[]{5,5,5,5,20,20,5,5,5,5});
    }
}
